#!/bin/bash

job_create_fstab()
{
	# initialize error handling
	trap error_handler ERR

	msg_job_start "job_create_fstab"

	#
	# create fresh fstab on target
	#
	# at first clean fstab first from all current /dev entries
	#
	msg "Cleaning target fstab at first"
	sed -i -e '/^\/dev/d' ${mountpoint}/etc/fstab

	# add root filesystem
	msg "Creating fstab entry for /"
	_device=`echo /dev/${target_root}`
	_uuid=`blkid "${_device}" -s UUID -o value`

	echo "UUID=${_uuid} / ${target_root_fs} defaults 0 0" >>${mountpoint}/etc/fstab
	unset _uuid
	unset _device

	# add swap filesystem
	if [ "${use_swap}" = "yes" ] ; then
		msg "Creating fstab entry for swap"

		_device=`echo /dev/${target_swap}`
		_uuid=`blkid "${_device}" -s UUID -o value`
		echo "UUID=${_uuid} swap swap defaults 0 0" >>${mountpoint}/etc/fstab
		unset _uuid
		unset _device
	else
		msg "Not using a swap partition"
	fi

	msg_job_done
}
